package case5_9;

import java.util.Scanner;

public class case7 {
    public static void main(String[] args) {
       /* 查找：已知一个数组arr={19,28,37,46,50}；键盘录入一个数据，
         查找该数据在数组中的索引，并在控制台输出找到的索引值。*/
       int [] arr = {19,28,37,46,50};
        System.out.println("请录入数组{19,28,37,46,50}中的数据：");
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();

        /*int index = -1;
        for (int i = 0; i < arr.length; i++) {
            if (number == arr[i]) {
                index = i;
                break;
            }
        }*/
        //调用方法
        int index = getindex(arr,number);
        System.out.println("index：" + index);
    }
    //设计一个查找方法
    public static int getindex (int [] arr , int number) {
        int index = -1;
        for (int i = 0; i < arr.length; i++) {
            if (number == arr[i]) {
                index = i;
                break;
            }
        }
        return index;
    }
}
